﻿package mortal.game.view.tianDiRank.panel
{
    import com.gengine.resource.*;
    import com.gengine.utils.*;
    import com.mui.controls.*;
    import com.mui.utils.*;
    import extend.language.*;
    import flash.display.*;
    import flash.events.*;
    import flash.geom.*;
    import frEngine.primitives.object2d.*;
    import mortal.common.global.*;
    import mortal.component.gconst.*;
    import mortal.component.window.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.manager.window3d.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.view.common.*;
    import mortal.game.view.tianDiRank.data.*;
    import mortal.game.view.tianDiRank.item.*;
    import mortal.mvc.core.*;

    public class TianDiRankDiShowPanel extends GSprite
    {
        protected var _bg:GBitmap;
        protected var _window:Window;
        private var _playerList:Array;
        private var _pNum:int = 5;
        protected var _tip:GBitmap;
        protected var _ruleBtn:GButton;
        protected var _timeDes:GTextFiled;
        protected var _accBtn:GLoadedButton;
        public var isDiRankFlag:Boolean = true;
        public var leftTime:SecTimerView;
        protected var _rect3d:Rect3DObject;
        protected var _img2d:Img2D;
        private var _wid:int = 889;
        private var _hei:int = 528;
        private var _markX:int = 11;
        private var _markY:int = 64;
        private var _posAvaArr:Array;

        public function TianDiRankDiShowPanel(param1:Window = null)
        {
            this._playerList = [];
            this._posAvaArr = [[435, 323], [240, 398], [641, 389], [85, 465], [795, 457], [345, 500]];
            this._window = param1;
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._bg = UIFactory.gBitmap("");
            this._tip = UIFactory.gBitmap(ImagesConst.TianDiRankListTip, 30, 73, this._window.contentTopOf3DSprite);
            this._ruleBtn = UIFactory.gButton("" + Language.getString(71968), 266, 64, 80, 30, this._window.contentTopOf3DSprite, "GreenLinkButton");
            this._timeDes = UIFactory.gTextField("" + Language.getString(71973), 32, 93, 200, 25, this._window.contentTopOf3DSprite, GlobalStyle.textFormatLv.setSize(15));
            this._accBtn = UIFactory.gLoadedButton(ImagesConst.TianDiRankChallengAcceBtn_upSkin, 217, 95, 42, 21, this._window.contentTopOf3DSprite);
            this._accBtn.label = "";
            LoaderManager.instance.load(ImagesConst.TianDiRankBg + ".swf", this.onBgLoadCompl);
            this.leftTime = UIFactory.secTimeView("hh:mm:ss", 0, 0, 100, 100, null);
            this.leftTime.configEventListener(EventName.SecViewTimeChange, this.onTimeChange);
            this._ruleBtn.configEventListener(MouseEvent.CLICK, this.showDetail);
            this._accBtn.configEventListener(MouseEvent.CLICK, this.onAcceleHd);
            this.setToolData();
            return;
        }// end function

        private function setToolData() : void
        {
            var _loc_1:* = "" + Language.getString(71969) + Language.getString(71970) + "" + Language.getString(71971);
            this._ruleBtn.toolTipData = "" + _loc_1;
            return;
        }// end function

        protected function onBgLoadCompl(param1) : void
        {
            if (isDisposed)
            {
                return;
            }
            this._bg.bitmapData = param1.bitmapData as BitmapData;
            this.init3DRect();
            this.add3dBg();
            this.initRoleModel();
            Dispatcher.dispatchEvent(new DataEvent(EventName.TianDiRankGetListInfo));
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            this._bg.dispose(param1);
            this._bg = null;
            this._ruleBtn.toolTipData = null;
            this._bg = null;
            this._tip = null;
            this._ruleBtn = null;
            this._timeDes = null;
            this._accBtn = null;
            this.leftTime.dispose(param1);
            this.leftTime = null;
            this.remove3D();
            return;
        }// end function

        private function onTimeChange(event:DataEvent) : void
        {
            if (this.leftTime == null)
            {
                return;
            }
            if (this.leftTime.secTimerViewData == null)
            {
                this.leftTime.stop();
                return;
            }
            var _loc_2:* = this.leftTime.secTimerViewData.hh();
            var _loc_3:* = this.leftTime.secTimerViewData.mm();
            var _loc_4:* = this.leftTime.secTimerViewData.ss();
            this._timeDes.htmlText = Language.getString(71972) + HTMLUtil.addColor(_loc_2 + "：" + _loc_3 + "：" + _loc_4, "#ff0000");
            if (this.leftTime.secTimerViewData.leftTime == 0)
            {
                this._timeDes.htmlText = Language.getString(71972) + _loc_2 + "：" + _loc_3 + "：" + _loc_4;
                this.setCDBtn(false);
            }
            return;
        }// end function

        private function setCDBtn(param1:Boolean) : void
        {
            if (param1)
            {
                this._accBtn.enabled = true;
                this._accBtn.filters = null;
            }
            else
            {
                this._accBtn.enabled = false;
                this._accBtn.filters = [FilterConst.colorFilter2];
            }
            return;
        }// end function

        protected function remove3D() : void
        {
            var _loc_1:TianDiPlayerSp = null;
            var _loc_2:int = 0;
            if (this._rect3d)
            {
                if (this._img2d)
                {
                    this._rect3d.removeImg(this._img2d);
                    this._img2d = null;
                }
                _loc_2 = 0;
                while (_loc_2 < this._playerList.length)
                {
                    
                    _loc_1 = this._playerList[_loc_2];
                    _loc_1.dispose();
                    _loc_1 = null;
                    _loc_2++;
                }
                this._playerList = [];
                Rect3DManager.instance.disposeRect3d(this._rect3d);
                this._rect3d = null;
            }
            return;
        }// end function

        protected function init3DRect() : void
        {
            this._rect3d = Rect3DManager.instance.registerWindow(true, new Rectangle(this._markX, this._markY, this._wid, this._hei), this._window);
            Rect3DManager.instance.windowShowHander(null, this._window);
            return;
        }// end function

        protected function add3dBg() : void
        {
            if (this._rect3d)
            {
                this._rect3d.removeImg(this._img2d);
                this._img2d = new Img2D(null, this._bg.bitmapData, new Rectangle(0, 0, this._wid, this._hei), false);
                this._rect3d.addImg(this._img2d);
            }
            return;
        }// end function

        private function showDetail(event:MouseEvent) : void
        {
            TianDiRankUtil.isCkShowPos = true;
            Dispatcher.dispatchEvent(new DataEvent(EventName.TianDiRankPosAttListCk, this.isDiRankFlag));
            return;
        }// end function

        private function onAcceleHd(event:MouseEvent) : void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.TianDiRankAccelerationCDCk));
            return;
        }// end function

        protected function initRoleModel() : void
        {
            var _loc_1:TianDiPlayerSp = null;
            var _loc_2:int = 0;
            if (this._rect3d)
            {
                _loc_2 = 0;
                while (_loc_2 < this._pNum)
                {
                    
                    _loc_1 = UICompomentPool.getUICompoment(TianDiPlayerSp);
                    _loc_1.initModule(this._rect3d);
                    this._playerList.push(_loc_1);
                    _loc_1.x = this._posAvaArr[_loc_2][0] - 16;
                    _loc_1.y = this._posAvaArr[_loc_2][1] - 203;
                    this._window.contentTopOf3DSprite.addChild(_loc_1);
                    _loc_2++;
                }
            }
            return;
        }// end function

        public function updateListInfo(param1:Boolean) : void
        {
            var _loc_4:TianDiPlayerSp = null;
            var _loc_6:int = 0;
            var _loc_7:Object = null;
            if (this.isDiRankFlag != param1)
            {
                return;
            }
            if (this._bg == null || this._bg.bitmapData == null)
            {
                return;
            }
            this.updateCDBtn(param1);
            var _loc_2:* = param1 ? (0) : (1);
            var _loc_3:* = Cache.instance.tianDi.mainIdArr[_loc_2];
            if (_loc_3 == null || this._playerList == null)
            {
                return;
            }
            var _loc_5:int = 0;
            while (_loc_5 < _loc_3.length)
            {
                
                _loc_6 = _loc_3[_loc_5];
                _loc_7 = TianDiRankUtil.getOnePlayerInfo(Cache.instance.tianDi.getPlayerInfo(_loc_2, _loc_6), _loc_5);
                _loc_4 = this._playerList[_loc_5];
                if (_loc_4 && _loc_7)
                {
                    _loc_4.updatePlayerInfo(_loc_7, _loc_5, this._posAvaArr[_loc_5][0], this._posAvaArr[_loc_5][1]);
                }
                _loc_5++;
            }
            return;
        }// end function

        public function updateCDBtn(param1:Boolean) : void
        {
            var _loc_2:int = 0;
            if (param1)
            {
                _loc_2 = Cache.instance.tianDi.selfCdTime;
            }
            else
            {
                _loc_2 = Cache.instance.tianDi.tianSelfCdTime;
            }
            if (_loc_2 > 0)
            {
                this.leftTime.setLeftTime(_loc_2);
                this.setCDBtn(true);
            }
            else
            {
                this.leftTime.stop();
                this._timeDes.text = "" + Language.getString(71973);
                this.setCDBtn(false);
            }
            return;
        }// end function

    }
}
